package flc.ast.adapter;


import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.stark.picselect.entity.SelectMediaEntity;

import flc.ast.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class PictureAdapter extends StkProviderMultiAdapter<SelectMediaEntity> {

    public PictureAdapter() {
        addItemProvider(new StkSingleSpanProvider(126));
        addItemProvider(new PictureProvider());
    }

    private class PictureProvider extends BaseItemProvider<SelectMediaEntity> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_picture;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, SelectMediaEntity bean) {
            Glide.with(baseViewHolder.itemView).load(bean.getPath()).into((ImageView) baseViewHolder.getView(R.id.ivPictureItemImg));
            baseViewHolder.setText(R.id.tvPictureItemName, FileUtils.getFileName(bean.getPath()));
            baseViewHolder.setText(R.id.tvPictureItemDate, TimeUtils.millis2String(FileUtils.getFileLastModified(bean.getPath()), "yyyy-MM-dd HH:mm"));
            baseViewHolder.setText(R.id.tvPictureItemSize, ConvertUtils.byte2FitMemorySize(FileUtils.getFileLength(bean.getPath()), 1));
            if (bean.isChecked()) {
                baseViewHolder.getView(R.id.ivPictureItemSel).setVisibility(View.VISIBLE);
            } else {
                baseViewHolder.getView(R.id.ivPictureItemSel).setVisibility(View.INVISIBLE);
            }
        }
    }

}
